import { defineStore } from "pinia";
import { login } from '@/api/login'
import { ref } from 'vue'


export const useLoginStore = defineStore('login', () => {


    const token = ref(localStorage.getItem('token') || '')
    //   const userInfo = ref(JSON.parse(localStorage.getItem('userInfo') || '{}'))
    console.log(token.value)

    // 登录
    const loginAction = async (loginData) => {
        try {
            const res = await login(loginData);
            if (res.code === 200) {
                token.value = res.data;
                localStorage.setItem('token', res.data)
            }
            return res;
        } catch (error) {
            throw error
        }
    }

    return {
        loginAction,
        token
    }


})